//
//  ESNewsWordSearchDetailCell.m
//  EasyStyle
//
//  Created by FK on 16/5/11.
//  Copyright © 2016年 FK. All rights reserved.
//

#import "ESNewsWordSearchDetailCell.h"



@implementation ESNewsWordSearchDetailCell

- (void)awakeFromNib {
    
    self.backgroundColor = [UIColor colorWithHex:@"eaeaea"];
    self.bgVIew.backgroundColor = [UIColor whiteColor];
    self.bgVIew.layer.cornerRadius = 1.0;
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    _newsContent.text = [ESNewsWordSearchDetailCell filtrateUselessWord:_searchResult.content];
    _newsContent.font = ESFontWithSize(14);
    
    _newsTitle.text = _searchResult.title;
    _newsTitle.font = ESFontWithSize(16);
    _newsSrc.text = _searchResult.src;
    
    _newsPushTime.text = _searchResult.pdate;
    
}


+ (NSString *)filtrateUselessWord:(NSString *)sourceString
{
    NSString *aString = @"<em>";
    NSString *bString = @"</em>";
    NSString *filtratedStr = [sourceString stringByReplacingOccurrencesOfString:aString withString:@""];
    filtratedStr = [filtratedStr stringByReplacingOccurrencesOfString:bString withString:@""];

    return filtratedStr;
}

+ (CGFloat)getLabelRectWithText:(NewsWordsDetailItem *)labelItem
{
    NSStringDrawingOptions options =  NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineBreakMode:NSLineBreakByCharWrapping];
    
    NSDictionary *tittleAttributes = @{ NSFontAttributeName : ESFontWithSize(16), NSParagraphStyleAttributeName : style };
    CGRect tittleLabelSize = [[ESNewsWordSearchDetailCell filtrateUselessWord:labelItem.title] boundingRectWithSize:CGSizeMake(ScreenWidth-20, CGFLOAT_MAX) options:options attributes:tittleAttributes context:nil];
    
    NSDictionary *attributes = @{ NSFontAttributeName : ESFontWithSize(14), NSParagraphStyleAttributeName : style };
    CGRect contentLabelSize = [[ESNewsWordSearchDetailCell filtrateUselessWord:labelItem.content] boundingRectWithSize:CGSizeMake(ScreenWidth-20, CGFLOAT_MAX) options:options attributes:attributes context:nil];
    
    return tittleLabelSize.size.height + contentLabelSize.size.height + 12 +16 + 30; //16为bgView上下边距  12为来源Viewheight
    
//    return contentLabelSize;
    
}


@end
